﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Client.Cache
{
    class ParamitersCache : CacheObject
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="ParamitersCache" /> class.
        /// </summary>
        public ParamitersCache()
            : base()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ParamitersCache" /> class.
        /// </summary>
        /// <param name="folder">The folder.</param>
        public ParamitersCache(string folder)
            : base(folder)
        {

        }

        /// <summary>
        /// Check value in cache.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <param name="paramiterId">The paramiter id.</param>
        /// <returns>Return true if value exist in cache/</returns>
        public bool Try(int projectId, int paramiterId)
        {
            return this.Try(this.GenerateKey(projectId, paramiterId));
        }

        /// <summary>
        /// Gets the value from cache.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <param name="paramiterId">The paramiter id.</param>
        /// <returns></returns>
        public byte[] Get(int projectId, int paramiterId)
        {
            return this.Get(this.GenerateKey(projectId, paramiterId));
        }

        public void Set(int projectId, int paramiterId, byte[] value)
        {
            return this.Set(this.GenerateKey(projectId, paramiterId), value, DateTime.Now + DateTime);
        }

        /// <summary>
        /// Generates the key use to allock value.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <param name="paramiterId">The paramiter id.</param>
        /// <returns>Key as string</returns>
        private string GenerateKey(int projectId, int paramiterId)
        {
            return projectId.ToString() + "/" + paramiterId.ToString();
        }
    }
}
